package org.xlp.base.application.dao;

import org.xlp.db.exception.EntityException;
import org.xlp.db.sql.DeleteSQL;
import org.xlp.mv.BaseDao;

import java.io.Serializable;

/**
 * Description: 应用基础操作数据功能类
 * <br/>date: 2023/12/15 10:52
 *
 * @version 1.0
 * @author: xlp
 */
public class ApplicationBaseDao extends BaseDao {
    ApplicationBaseDao(){}

    /**
     * 批量删除
     * @param entityClass
     * @param ids
     * @param <T>
     * @return
     */

    @SuppressWarnings("all")
    public <T> int deleteBatch(Class<T> entityClass, Serializable[] ids){
        DeleteSQL<T> deleteSQL = new DeleteSQL<>(entityClass);
        String[] names = deleteSQL.getPrimaryKey().getNames();
        if (names.length != 1){
            throw new EntityException(entityClass + "实体不是单主键，不支持该批量删除操作！");
        }
        deleteSQL.andIn(names[0], ids);
        return delete(deleteSQL);
    }
}
